package fun.yyds.config.websocket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册WebSocket处理器，设置访问路径和允许跨域
        registry.addHandler(dataPushHandler(), "/ws/dataPush")
                .setAllowedOrigins("*");
    }

    @Bean
    public DataPushHandler dataPushHandler() {
        return new DataPushHandler();
    }
}
